<?php

namespace Modules\Asset\Exports;

use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;

// use PHPExcel_Cell_DataType;
use PhpOffice\PhpSpreadsheet\Cell\DataType;

use Modules\Asset\Entities\PackageSku;

class PackageSkuExport implements WithColumnFormatting, FromCollection, WithTitle, WithHeadings, WithMapping, ShouldAutoSize
{
    use Exportable;

    private $list;

    public function __construct($list)
    {
        $this->list = $list;
    }

    public function columnFormats(): array
    {
        return [];
        // return [
        //     'O' => DataType::TYPE_STRING
        // ];
    }

    /**
     * @return Builder
     */
    public function collection()
    {
        return $this->list;
        // return BookInfo::where('booking_session_id', $this->session->id)->displayed();
    }

    /**
     * @return string
     */
    public function title(): string
    {
        return '记录导出';
    }

    public function map($item): array
    {
        $user = $item->user;

        $res = [
            $item->id,
            $item->sid,
            $item->title,
            $item->number,
            $item->money_price / 100,
            $item->score_price,
            $item->total,
            @$user->name,
            @$user->phone,
            $user->status === 1 ? '正常' : '已禁用',
            $item->node_title,
            $item->source_type_text,
            $item->union_status_text,
            $item->created_at,
            $item->picked_at,
            $item->resaled_at,
            $item->return_saled_at,
            $item->return_score,
            $item->return_money / 100,
            $item->return_redpack / 100
        ];

        return $res;
    }

    public function headings(): array
    {
        return [
            '唯一ID',
            'SID',
            '物品名',
            '物品编号',
            '物品价值(人民币)',
            '物品价值(积分)',
            '物品数量',
            '用户名',
            '手机号',
            '用户状态',
            '所属活动',
            '获得途径',
            '物品状态',
            '获得时间',
            '提货时间',
            '转售时间',
            '回收时间',
            '回收(积分)',
            '回收(原路返回)',
            '回收(红包)余额'
        ];
    }
}
